package com.iscas.green.extralindextest.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 安全Servlet，需要通过SecurityFilter验证才能访问
 */
@WebServlet(name = "secureServlet", urlPatterns = "/servlet/secure/data")
public class SecureServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private static final Logger log = LoggerFactory.getLogger(SecureServlet.class);

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        log.info("SecureServlet收到GET请求");
        
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println("<html><body>");
        response.getWriter().println("<h2>安全Servlet</h2>");
        response.getWriter().println("<p>您已成功通过安全验证！</p>");
        response.getWriter().println("<p>当前时间: " + new java.util.Date() + "</p>");
        
        // 获取安全头信息
        String secretHeader = request.getHeader("X-API-Secret");
        response.getWriter().println("<p>使用的安全密钥: " + secretHeader + "</p>");
        
        response.getWriter().println("</body></html>");
    }
} 